package com.gxa.modules.service.impl;

import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.PageRecv;
import com.gxa.modules.mapper.OverdueMapper;
import com.gxa.modules.pojo.Overdue;
import com.gxa.modules.service.OverdueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class OverdueServiceImpl implements OverdueService {
    @Autowired(required = false)
    private OverdueMapper overduemapper;
    @Override
    public JsonResult queryOverdue(Integer page, Integer limit) {
        JsonResult jsonResult = new JsonResult();
        Integer param1 = (page - 1)*limit;
        Integer param2 = limit;
        List<Map> collectionMap = overduemapper.queryOverdue(param1,param2);
        int result = overduemapper.countOverdue();
        jsonResult.setCount(result);
        jsonResult.setData(collectionMap);
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功");
        return jsonResult;
    }

    @Override
    public JsonResult searchOverdueList(PageRecv<Overdue> pageRecv) {
        //对查询页面参数计算
        Integer currentPage=pageRecv.getCurrentPage();
        Integer pageSize=pageRecv.getPageSize();
        Integer limit1=(currentPage-1)*pageSize;
        pageRecv.setCurrentPage(limit1);
        Overdue overdue=pageRecv.getData();
        //调用mapper方法，返回查询结果list
        List<Overdue> list=overduemapper.searchOverdueListMapper(pageRecv);
        Integer count=overduemapper.searchOverdueListCountMapper(pageRecv);
        //将list和count条数塞入r,响应成功返回
        JsonResult r=new JsonResult();
        r.setCode(200);
        r.setCount(count);
        r.setMsg("查询成功");
        r.setData(list);
        return r;
    }
}
